import {isRealNode} from "../../../core/vdom/utils";
import {hasOwn, isDef} from "../../../shared/util";

/**
 *
 * @param {Node | VNode} oldNode
 * @param {VNode} newNode
 */
function updateProps (oldNode, newNode) {
    let elem = null;
    isRealNode(oldNode)
        ? elem = oldNode
        : elem = newNode.elem;

    if (!hasOwn(oldNode, 'key') || oldNode.key !== newNode.key) {
        elem.key = newNode.key;
    }

    if (oldNode.textContent !== newNode.textContent) {
        isDef(newNode.textContent)
            ? elem.textContent = newNode.textContent
            : elem.textContent = "";
    }
}

export default {
    mount: updateProps,
    update: updateProps,
}
